package com.iflytek.springboot_medicine.service.impl;

import com.iflytek.springboot_medicine.entity.Category;
import com.iflytek.springboot_medicine.pojo.OrderPojo;
import com.iflytek.springboot_medicine.service.OrderPojoRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class OrderPojoServiceImpl {
    private final OrderPojoRepository repo;
    public OrderPojoServiceImpl(OrderPojoRepository repo) {
        this.repo = repo;
    }
    /**
     *分页查询
     * @param pageNum
     * @param pageSize
     * @return
     */
    public Page<OrderPojo> findOrderPojo(int pageNum, int pageSize) {
        // 构建分页请求
        Pageable pageable = PageRequest.of(pageNum - 1, pageSize);
        // 执行分页查询
        return repo.findAll(pageable);
    }

    public OrderPojo deleteOrderPojoById(int id) {
        return repo.deleteById(id);
    }

    /**
     * 批量删除订单
     */
    public void deleteAllInBatch(List<Integer> ids) {
        repo.deleteAllByIdInBatch(ids);
    }
}
